package com.atguigu.yygh.user.controller;/*
 * @author: XueYouPeng
 * @time: 2023/6/16 16:18
 */

import com.atguigu.common.result.Result;
import com.atguigu.yygh.enums.AuthStatusEnum;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

//后台管理系统
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;

    /* 后台管理系统中，查询用户列表
     * 查询所有的认证状态
     * @author: XueYouPeng
     * @time: 2023/6/16 16:19
     */
     @PostMapping("/selectPage/{pageNum}/{pageSize}")
     public Result selectPage(
             @PathVariable Integer pageNum,
             @PathVariable Integer pageSize,
             @RequestBody UserInfoQueryVo userInfoQueryVo
             ){
         Page<UserInfo> page = userInfoService.selectPage(pageNum,pageSize,userInfoQueryVo);
         return Result.ok().data("list",page.getRecords()).data("total",page.getTotal());
     }

     //更改用户状态
     @GetMapping("updateStatus/{userId}/{status}")
     public Result updateStatus(@PathVariable Long userId,@PathVariable Integer status){
         userInfoService.updateStatus(userId,status);
         return Result.ok();
     }

     //查看用户详情
     @GetMapping("show/{userId}")
     public Result show(@PathVariable Long userId){
         Map<String,Object> map = userInfoService.show(userId);
         return Result.ok().data(map);
     }

     //通过和驳回的接口
     @GetMapping("authUser/{userId}/{authStatus}")
     public Result authUser(@PathVariable Long userId,@PathVariable Integer authStatus ){
         userInfoService.authUser(userId,authStatus);
         return Result.ok();
     }

     //校验身份证的接口 引用阿里云
     //校验姓名和证件号码是否匹配
     @GetMapping("/check/{name}/{idCard}")
     public Result checkNameAndIdCard(@PathVariable String name,@PathVariable String idCard){
         Boolean bo = userInfoService.check(name,idCard);
         return bo?Result.ok():Result.error();
     }

    /**
     * 查询所有的认证状态
     * @return
     */
     @GetMapping("findAuthStatusList")
     public Result findAuthStatusList(){
         //认证状态的所有的枚举值，每个枚举两个属性
         AuthStatusEnum[] values = AuthStatusEnum.values();

         ArrayList<Map<String,Object>> list = new ArrayList<>();

         HashMap<String, Object> map = new HashMap<>();
         map.put("name","查询所有");
         map.put("status",-2);

         list.add(map);

         for (AuthStatusEnum value : values){
             Integer status = value.getStatus();
             String name = value.getName();

             HashMap<String, Object> m = new HashMap<>();
             m.put("name",name);
             m.put("status",status);
             list.add(m);
         }
         return Result.ok().data("list",list);
     }



}
